package com.activity.cycle;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

/**
 * MainActivity——>NewActivity
 * onCreate——>onStart——>onResume——>onPause——>onCreate_new——>onStart_new——>onResume_new——>onStop
 * <p>
 * NewActivity——>onBackPressed, NewActivity.this.finish();
 * onPause_new——>onRestart——>onStart——>onResume——>onStop_new——>onDestroy_new
 * <p>
 * NewActivity——>startActivity(new Intent(NewActivity.this, MainActivity.class)); finish();
 * onPause_new——>onCreate——>onStart——>onResume——>onStop_new——>onDestroy_new
 * <p>
 * NewActivity——>startActivity(new Intent(NewActivity.this, MainActivity.class));
 * onPause_new——>onCreate——>onStart——>onResume——>onStop_new
 */
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i("activityLog", "MainActivity onCreate");
        Button btn = findViewById(R.id.btn_go);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivityForResult(new Intent(MainActivity.this, NewActivity.class), 1);
                //                startActivity(new Intent(MainActivity.this, NewActivity.class));
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (null != data) {
            String stringExtra = data.getStringExtra("data");
            Log.i("activityLog", "stringExtra = " + stringExtra);
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.i("activityLog", "MainActivity onRestart");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.i("activityLog", "MainActivity onStart");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.i("activityLog", "MainActivity onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i("activityLog", "MainActivity onPause");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.i("activityLog", "MainActivity onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i("activityLog", "MainActivity onDestroy");
    }

}
